package com.sky.mapper;

import com.sky.entity.AddressBook;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AddressBookMapper {

    @Insert(" insert into address_book values (null,#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void addAddressBook(AddressBook addressBook);

    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> list(Long userId);

    AddressBook getDefault();

    @Delete("delete from address_book where id = #{id}")
    void delete(Long id);

    @Select("select * from address_book where id = #{id}")
    AddressBook getAddressBookById(Long id);

    void updateAddressBook(AddressBook addressBook);

    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateDefaultAddressBook(AddressBook addressBook);

    @Update("update address_book set is_default = #{isDefault} where id = #{id}")
    void updateDefault(AddressBook addressBook);
}
